if ( SERVER ) then
	AddCSLuaFile( "shared.lua" )
	
	resource.AddFile( "models/weapons/v_equaliz.mdl" )
	resource.AddFile( "models/weapons/w_equaliz.mdl" )
	resource.AddFile( "materials/models/props_mining/pickaxe01.vmt" )
	resource.AddFile( "materials/models/props_mining/Pickaxe01_normal2.vtf" )
	resource.AddFile( "materials/models/props_mining/pickaxenew.vtf" )
	resource.AddFile( "sound/weapons/equalizer/equalizer_hit1.wav" )
	resource.AddFile( "sound/weapons/equalizer/equalizer_swing1.wav" )
	resource.AddFile( "materials/HUD/killicons/equalizer.vtf" )
	resource.AddFile( "materials/HUD/killicons/equalizer.vmt" )
	resource.AddFile( "materials/HUD/killicons/equalizerspawnicon.tga" )
end

if ( CLIENT ) then

	SWEP.DrawAmmo			= false
	SWEP.DrawCrosshair		= true
	SWEP.ViewModelFOV		= 60
	SWEP.ViewModelFlip		= false
	SWEP.CSMuzzleFlashes	= false
	
	killicon.Add( "weapon_equalizerthing", "HUD/killicons/equalizer", Color( 255, 80, 0, 100 ) )
end

SWEP.PrintName 		= "PickAxe"
SWEP.Author			= "kiwi"
SWEP.Purpose		= "Swing to mine"
SWEP.Instructions	= "Mine for ores"

SWEP.Slot				= 2
SWEP.SlotPos			= 1

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= false

SWEP.HoldType			= "melee"

SWEP.ViewModel = "models/weapons/v_equaliz.mdl"
SWEP.WorldModel = "models/weapons/w_equaliz.mdl"

SWEP.Primary.Sound			= ""
SWEP.Primary.Recoil			= 0
SWEP.Primary.Damage			= 15
SWEP.Primary.NumShots		= 0
SWEP.Primary.Cone			= 0
SWEP.Primary.Delay			= 1.2

SWEP.NextStrike = 0;

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "none"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"

SWEP.PreviousPosition 		= Vector(0, 0, 0)
SWEP.PreviosAim				= Vector(0, 0, 0)

function SWEP:Initialize()
	self:SetWeaponHoldType( self.HoldType )
end

function SWEP:Deploy()
	self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
	self:SetNextPrimaryFire(CurTime() + 0.7)
	self:SetNextSecondaryFire(CurTime() + 0.7)
	self.PreviousPosition = self.Owner:GetShootPos()
	self.PreviousAim = self.Owner:GetAimVector()
	return true
end

function SWEP:Precache()
end

function SWEP:Holster()
	return true
end

function SWEP:PrimaryAttack()
	if( CurTime() < self.NextStrike ) then return end
	self.Weapon:EmitSound("weapons/equalizer/equalizer_swing1.wav")
	TraceEyesResult = self.Owner:GetEyeTrace()
	self.NextStrike = ( CurTime() + 0.8 );
	self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	if( TraceEyesResult.HitPos:Distance(self.Owner:GetShootPos()) <= 100 ) then
		if TraceEyesResult.MatType == MAT_CONCRETE ||  TraceEyesResult.MatType == MAT_DIRT then
			if (SERVER) then -- might need to do prediction here on the client?
				self.Owner:DoWork("Mining")
			end
		end
		
		self:DoHit()
		self.Weapon:EmitSound("weapons/equalizer/equalizer_hit1.wav")
		self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
	end
end

function SWEP:SecondaryAttack()
	if (SERVER) then
		self.Owner:StopWork()
	end
end

function SWEP:DoHit()
			bullet = {}
				bullet.Num    = 1
				bullet.Src    = self.Owner:GetShootPos()
				bullet.Dir    = self.Owner:GetAimVector()
				bullet.Spread = Vector(0, 0, 0)
				bullet.Tracer = 0
				bullet.Force  = 8
				bullet.Damage = self.Primary.Damage
			self.Owner:FireBullets(bullet)
	--if (SERVER) then
	--	self.Owner:TraceHullAttack( self.Owner:GetShootPos(), self.Owner:GetAimVector() * 100, Vector(-16,-16,-16), Vector(36,36,36), SWEP.Primary.Damage, DMG_SLASH, 1, true )
	--end
end
